import React from 'react'
import Login from './container/login/login'
import Register from './container/register/register'
import BossInfo from './container/bossinfo/bossinfo'
import GeniusInfo from './container/geniusinfo/geniusinfo'
import AuthRoute from './component/authroute/authroute'
import Dashboard from './component/dashboard/dashboard'
import Chat from './component/chat/chat'

import { Route, Switch } from 'react-router-dom'

class App extends React.Component {
  constructor () {
    super()
    this.state = {
      hasError: false
    }
  }
  // react 16 新加的统一的错误处理
  componentDidCatch (err, info) {
    console.log(err, info)
    this.setState({
      hasError: true
    })
  }
  render () {
    return this.state.hasError ?
      <h2 style={{textAlign: 'center'}}>抱歉，页面出错了</h2>
     : (
      <div>
        {/* 控制跳转的组件 */}
        <AuthRoute />
        {/* 只命中一个路由 */}
        <Switch>
          <Route path='/bossinfo' component={BossInfo} />
          <Route path='/geniusinfo' component={GeniusInfo} />
          <Route path='/login' component={Login} />
          <Route path='/register' component={Register} />
          <Route path='/chat/:user' component={Chat} />
          <Route component={Dashboard} />
        </Switch>
      </div>
    )
  }
}

export default App